//
//  SecondViewController.m
//  UI_07_delegate_block
//
//  Created by li cheng on 16/7/22.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "SecondViewController.h"
#import "FirstViewController.h"


@interface SecondViewController ()
@property (nonatomic, strong) UITextField *textField;
@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 100, 60)];
    self.textField.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.textField];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor yellowColor];
    button.frame = CGRectMake(100, 180, 100, 60);
    [self.view addSubview:button];
    [button addTarget:self action:@selector(comeBack:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)comeBack:(UIButton *)button{
    // 可以从后往前传,不建议这么写
//    NSInteger count = self.navigationController.viewControllers.count;
//    FirstViewController *first = self.navigationController.viewControllers[count - 2];
//    first.titleLabel.text = self.textField.text;
//    [self.navigationController popViewControllerAnimated:YES];
#warning 触发协议方法 (判断delegate存不存在,判断签订delegate的类有没有实现协议方法)
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValue:)]) {
        [self.delegate passValue:_textField.text];
    }
    [self.navigationController popViewControllerAnimated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
